<?php

if (!defined('XOOPS_ROOT_PATH')) exit();

require_once XOOPS_MODULE_PATH. '/scuttle/class/AbstractListAction.class.php';
require_once XOOPS_MODULE_PATH. '/scuttle/admin/forms/TagsAdminFilterForm.class.php';
require_once XOOPS_MODULE_PATH. '/scuttle/admin/include/functions.php';

class Scuttle_TagsListAction extends Scuttle_AbstractListAction
{
	var $tagsArray = null;

	var $breadCrumbs     = null;
	var $confirmMssage   = null;
	var $moduleHeader    = null;

	var $mPagenavi         = null;
	var $totalCount        = null;

	function _getStart()
	{
		return xoops_getrequest('start');
	}

	function _getSort()
	{
		return xoops_getrequest('sort');
	}

	function &_getHandler()
	{
		$handler =& xoops_getmodulehandler('tags');
		return $handler;
	}


	function &_getFilterForm()
	{
		$filter =& new Scuttle_TagsFilterForm($this->_getPageNavi(), $this->_getHandler());
		return $filter;
	}

	function _getBaseUrl()
	{
		return 'index.php?action=TagsList';
	}

	function &_getPageNavi()
	{
		$navi =& parent::_getPageNavi();

		$navi->setStart($this->_getStart());
		$navi->setPerpage(20);
		$navi->setTotalItems($this->totalCount);
		return $navi;
	}

	function getDefaultView(&$controller, &$xoopsUser)
	{
		$this->mFilter =& $this->_getFilterForm();
		$this->mFilter->fetch();

		$handler =& $this->_getHandler();

		$perPage    = 20;
		$startEntry = $this->_getStart() ;

		$this->totalCount = $handler->adminCountTagWords();

		if (!$this->totalCount > 0) {
			$this->confirmMssage = _AD_SC_TAG_NOSUBMITTED ;
		} else {
			$this->tagsArray = $handler->adminTagList($perPage, $startEntry, $this->mFilter->getSort(), $this->mFilter->getOrder());
		}

		if ($this->totalCount > $perPage ) {
			$this->mPagenavi =$this->_getPageNavi();
		}

		$this->breadCrumbs[] = array('name' => _AD_SC_MAIN) ;

		return SC_FRAME_VIEW_INDEX;
	}

	function executeViewIndex(&$controller, &$xoopsUser, &$render)
	{
		global $adminmenu;

		$render->setTemplateName('scuttle_tags_list.html');
		$render->setAttribute('module_info'   , getModuleInfo());
		$render->setAttribute('module_header' , $this->moduleHeader);
		$render->setAttribute('bread_crumbs'  , $this->breadCrumbs);
		$render->setAttribute('set_menu'      , $adminmenu );
		$render->setAttribute('set_menu_no'   , 3);
		$render->setAttribute('confirm_mssage', $this->confirmMssage);
		$render->setAttribute('objects'       , $this->mObjects);
		$render->setAttribute('tag_array'       , $this->tagsArray);

		$render->setAttribute("sortNavi"   , $this->_getPageNavi());
		$render->setAttribute('pageNavi', $this->mPagenavi);
	}
}
?>